Skip to content

fix(studio): a sealed resize keeps the dragged corner on the pointer at fractional sizes - #8560

Merged
miguel-heygen merged 2 commits into
mainfrom
fix/sealed-resize-remainder
Nov 23, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
fix/sealed-resize-remainder

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What

In a sealed preview, the corner you drag in a resize now stays on the pointer. Before, it sat up to half a pixel short whenever the size the drag asked for wasn't a whole number, while an unsealed preview kept it exact. Sealed and unsealed now draw the same box.

Why

A resize writes whole-pixel sizes. To keep the dragged corner where the wanted, fractional size would put it, the unsealed draft moves the box by half the rounding remainder along its own edges (resizeRemainderShift, which reads the element's corners from the frame). A sealed frame can't be measured, so its draft pinned the box on the written size alone and dropped that remainder.

Related work

Follows the sealed resize centre fix (#8547): the same draft, the remainder it still left out.

How

packages/studio/src/components/editor/resizeDraft.ts: resizeRemainderShift stays the one owner of the remainder. The sealed draft builds the box's corners at the written size from the gesture's own centre, rotation and edit scale, and calls it with the same grab point the unsealed draft uses. The pin and the box Studio draws over the frame both move by that shift.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

fails without the fix: packages/studio/src/components/editor/resizeDraft.test.ts, "moves a sealed box by the same rounding remainder an unsealed draft measures". On main the sealed pin is 0.37 px off the remainder the unsealed draft measures for a 300.6 x 150.3 px wanted size on a turned, scaled box; with the fix it is within 0.07 px.

With the fix, on a Linux machine: resizeDraft.test.ts, domEditResizeLocal.test.ts, anchoredResizeReleaseShift.test.ts, previewDrafts.test.ts and DomEditOverlay.test.ts pass three runs in a row. The push gate's covering files, Studio tsc, Fallow and pre-push are clean.

Bench

Edit-accuracy bench on a Linux machine, the 13 scale resize cases, main at da7faad with and without this change, the same bench for both, two runs per mode. Worst value across the 13 cases, in px (a case fails over 0.5):

sealed, main sealed, this change unsealed, main unsealed, this change
tracking (box vs pointer while dragging) 0.53 / 0.53 0.23 / 0.28 0.19 / 0.19 0.19 / 0.19
drop 0.29 / 0.29 0.29 / 0.29 0.29 / 0.29 0.29 / 0.29
reload 0.27 / 0.27 0.30 / 0.30 0.27 / 0.27 0.27 / 0.27

The two -z50-after cases that failed on main at 0.52 to 0.53 now pass.

Still different sealed, not changed by this PR:

  • The -after cases settle 0.47 to 0.48 px from the pointer after release sealed, against 0.05 unsealed.
  • Under a heavily loaded machine, some sealed scale cases show a one-frame jump of about 60 px back to the start position right after release, then land on the drop point. It hit 7 of 26 case runs on main and 8 of 26 with this change, and none unsealed.

No visible change

Sealed previews are off by default, so nothing changes for anyone yet. With them on, a resized layer's corner stays under the pointer.

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 69 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at ba78559c.

  • The sealed draft now calls resizeRemainderShift with corners built from the gesture's centre, rotation and edit scale, and the same grab point as the unsealed draft (grabOf, shared by both). The shift is in overlay px, the same units the existing (w/2)*editScaleX term and the unsealed anchor target use. Only the sealed path passes wanted, so its one caller is the only change in behaviour.
  • Red first: with resizeDraft.ts from main, "moves a sealed box by the same rounding remainder an unsealed draft measures" fails. It passes at head.
  • resizeDraft, domEditResizeLocal, anchoredResizeReleaseShift, previewDrafts and DomEditOverlay tests pass locally. All CI is green.
  • Studio-only change with no CLI surface, so no docs are needed.

Nits (non-blocking):

  • The + shift.x / + shift.y on the returned overlay rect isn't pinned by a test. Dropping both keeps every test green.
  • gestureCorners assumes a rotated, uniformly edit-scaled box. When resizeGrow comes from a skewed or otherwise non-rotation transform, the sealed remainder direction can differ from what the unsealed draft measures. That is at most half the rounding remainder, so not a blocker; it's worth a case in the bench if skewed layers get sealed coverage.

Need ✅ · Size ✅ · Reuse ✅ (resizeRemainderShift stays the one owner) · Simpler ✅ · Structure ✅
Risk: low. Sealed previews are off by default, and the change is a sub-pixel draft shift.

— Rames (hf-review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit 4f5bfc2 Nov 23, 2026
125 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-resize-remainder branch November 23, 2026 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants